package com.only.common.util;


import com.only.common.exception.BizException;

/**
 * @author only
 * @date 2023/10/17
 * @description
 */
public class BooleanIntegerConverter {
    /**
     * true --> 1
     * false --> 0
     * @param b
     * @return
     */
    public static int boolean2Int(boolean b) {
        return b ? 1 : 0;
    }

    public static boolean intToBoolean(int i) {
        if (i == 0) {
            return false;
        }

        if (i == 1) {
            return true;
        }

        throw new BizException("500", "系统异常", new Throwable("无法将" + i + "转换为 boolean"));
    }
}
